/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Dr.Tree
 * Created On : May 13, 2012  11:27:03 AM 
 * e-Mail : chatree@tis.co.th
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : apps.business.process.sales.receipted
 * File Name : SdChargecodeProcessing.java
 * TODO
 */
package apps.business.process.sales.receipted;

import java.util.List;

import jpa.entitys.synchro.staging.FiArreceiptreOutb;
import jpa.entitys.synchro.staging.SdChargecode;

import org.apache.log4j.Logger;

import apps.promis.out.common.VwSyncRcvdInstallmentAction;
import apps.promis.out.sales.ReceiptedChargeCodeAction;

import sap.business.sd.outbound.SdChargecodeService;

/**
 * @author chatree
 *
 */
public class SdChargecodeProcessing {
	
	
	private static final Logger log = Logger.getLogger(SdChargecodeProcessing.class);

	/**
	 * 
	 */
	public SdChargecodeProcessing() {
		// TODO Auto-generated constructor stub
	}
	

	/**
	 * 		String company = "SP";
			String project = "SPLCITY-SRI";
			String ReceipteddocumentNo = "RR-1205-000024";
			String status = "A";
			String syncIsstaging = "Y";
	 * @param company
	 * @param project
	 * @param ReceipteddocumentNo
	 * @param status
	 * @param syncIsstaging
	 * @throws Exception
	 */
	public void Processing(String company, String project, String ReceipteddocumentNo, String status, String syncIsstaging) throws Exception {
		try{
			
			//Create to CreateRcvdToStaging
			List<FiArreceiptreOutb> RR_Installment_lst = new VwSyncRcvdInstallmentAction().CreateRcvdToStaging(company, project, ReceipteddocumentNo, status, syncIsstaging);
			log.info("Created Rcvd Installment To Staging ==========================================>");
			
			//Create ChargeCode To Staging
			ReceiptedChargeCodeAction receiptedChargeCodeAction = new ReceiptedChargeCodeAction();			
		    List<SdChargecode> newValueList = receiptedChargeCodeAction.CreateToStaging(RR_Installment_lst);
			
			//Sending ChargeCode to SAP
			SdChargecodeService SdChargecodeServ = new SdChargecodeService();
			SdChargecodeServ.SendingToSAP(newValueList);
			log.info("Sending Rcvd ChargeCode To Staging ==========================================>");
			
		}catch(Exception e)
		{
			log.error(e.getMessage());
			System.err.println(e.getMessage());
			throw e;
		}
	}
	
	@Deprecated
	private void Start() throws Exception {
		try{
			
			String company = "SP";
			String project = "SPLCITY-SRI";
			String ReceipteddocumentNo = "RR-1205-000024";
			String status = "A";
			String syncIsstaging = "Y";

			//Create to CreateRcvdToStaging
			log.info("Start Create Rcvd Installment To Staging ==========================================>");
			List<FiArreceiptreOutb> RR_Installment_lst = new VwSyncRcvdInstallmentAction().CreateRcvdToStaging(company, project, ReceipteddocumentNo, status, syncIsstaging);
			log.info("End Create Rcvd Installment To Staging ==========================================>");
			
			//Create ChargeCode To Staging
			ReceiptedChargeCodeAction receiptedChargeCodeAction = new ReceiptedChargeCodeAction();			
		    List<SdChargecode> newValueList = receiptedChargeCodeAction.CreateToStaging(RR_Installment_lst);
			
			//Sending ChargeCode to SAP
			log.info("Start Sending Rcvd ChargeCode To Staging ==========================================>");
			SdChargecodeService SdChargecodeServ = new SdChargecodeService();
			SdChargecodeServ.SendingToSAP(newValueList);
			log.info("End Sending Rcvd ChargeCode To Staging ==========================================>");
			
		}catch(Exception e)
		{
			log.error(e.getMessage());
			System.err.println(e.getMessage());
			throw e;
		}
	}

//	/**
//	 * @param args
//	 */
//	public static void main(String[] args) {
//		// TODO Auto-generated method stub
//		try{
//			
//			new SdChargecodeProcessing().Start();
//			
//		}catch(Exception e)
//		{
//			e.printStackTrace();
//			log.error(e);		
//		}
//	}

}
